package com.qianxun.watchdog.communication;

import java.io.IOException;


public class CommunicationService {
    private CommunicationAcceptor messageAcceptor;

    public static synchronized boolean run(int port ,MessageHandler messageHandler ,Callback overCallback) throws IOException {
        CommunicationService single = getInstance();
        if (single.messageAcceptor == null){
            single.messageAcceptor = new CommunicationAcceptor(port ,messageHandler ,overCallback);
            single.messageAcceptor.accept();
        }
        System.out.println("CommunicationService startup ,port :" + single.messageAcceptor.getPort());
        return true;
    }



    private static CommunicationService getInstance(){
        return Holder.INSTANCE;
    }

    private static final class Holder{
        static CommunicationService INSTANCE = new CommunicationService();
    }
}
